package com.hzhr.iot.device.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.device.dao.IotDeviceDao;
import com.hzhr.iot.device.entity.IotDeviceEntity;
import com.hzhr.iot.device.queryModel.custom.IotDeviceCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class IotDeviceDaoHelper {
    @Autowired
    IotDeviceDao iotDeviceDao;

    public IotDeviceEntity getByCodeAndCategoryCode(String code, String categoryCode) {
        if (StringUtils.isEmpty(code) || StringUtils.isEmpty(categoryCode)) return null;
        IotDeviceCustomQueryModel iotDeviceCustomQueryModel = new IotDeviceCustomQueryModel();
        iotDeviceCustomQueryModel.setEqual_code(code);
        iotDeviceCustomQueryModel.setEqual_categoryCode(categoryCode);
        iotDeviceCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        iotDeviceCustomQueryModel.setShow(true);
        IotDeviceEntity iotDeviceEntity = iotDeviceDao.selectEntity(iotDeviceCustomQueryModel);
        return iotDeviceEntity;
    }

    public int getCountByCodeAndCategoryCode(String code, String categoryCode) {
        if (StringUtils.isEmpty(code) || StringUtils.isEmpty(categoryCode)) return 0;
        IotDeviceCustomQueryModel iotDeviceCustomQueryModel = new IotDeviceCustomQueryModel();
        iotDeviceCustomQueryModel.setEqual_code(code);
        iotDeviceCustomQueryModel.setEqual_categoryCode(categoryCode);
        iotDeviceCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = iotDeviceDao.selectCount(iotDeviceCustomQueryModel);
        return count;
    }

    public IotDeviceEntity getById(int id) {
        IotDeviceCustomQueryModel iotDeviceCustomQueryModel = new IotDeviceCustomQueryModel();
        iotDeviceCustomQueryModel.setEqual_id(id);
        iotDeviceCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        iotDeviceCustomQueryModel.setShow(true);
        IotDeviceEntity iotDeviceEntity = iotDeviceDao.selectEntity(iotDeviceCustomQueryModel);
        return iotDeviceEntity;
    }
}
